<%--
  Created by IntelliJ IDEA.
  User: Lanan
  Date: 2017/12/18 0018
  Time: 17:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%--<%@ include file="/commons/basejs.jsp" %>--%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户账户信息添加</title>
</head>
<body>
<style>
    table td{
        font:100% arial,helvetica,sans-serif;
        /*text-align: center;*/
        height:20px;
        border:1px solid #e0e0e0;
        padding-left:5px;
        border: 1px solid #e0e0e0;
    }
    .td{
        width: 80px;
        /*background-color: rgb(242,242,242);*/
    }
</style>
<form id="insert_user_account_form" method="post">
    <table align="center" width="100%" style="margin-top: 20px" cellpadding="4">
        <input type="hidden" name="id"/>
        <tr>
            <td class="td" align="right" width="40%"><lable for="userId">用户:</lable></td>
            <td width="60%">
                <div style="position: relative;height:15px;width:150px;top:0.5px; display:inline-block;">
                    <input type="text" name="userId" id="userID" value="" hidden/>
                    <input type="text" id="autocomplete-ajax-search-account" style="position: absolute; z-index: 2; background: transparent;"/>
                    <input type="text" id="autocomplete-ajax-search-account-x" disabled="disabled" style="color: #CCC; position: absolute; background: transparent; z-index: 1;"/>
                </div>
            </td>
        </tr>
        <tr>
            <td class="td" align="right" width="40%"><lable for="type">账户类型:</lable></td>
            <td  width="60%">
                <select id="type" class="easyui-combobox" name="type" data-options="required:true,panelHeight:'auto',editable:false" style="width:160px;">
                    <option value="0" selected>银行卡</option>
                    <option value="1">支付宝</option>
                    <option value="2">微信</option>
                </select>
            </td>
        </tr>
        <tr id="bank_account_td">
            <td  class="td" align="right" width="40%"><lable for="bankAccount">银行卡号:</lable></td>
            <td  width="60%">
                <input id="bank_account" name="bankAccount" class="easyui-numberbox" data-options="missingMessage:'请输入银行卡号', validType:'number', required:true" style="width:150px;"/>
            </td>
        </tr>
        <tr id="wechat_account_td">
            <td  class="td" align="right" width="40%"><lable for="wechatAccount">微信账号:</lable></td>
            <td  width="60%">
                <input id="wechat_account" name="wechatAccount" class="easyui-validatebox" data-options="missingMessage:'请输入微信账号', required:true" style="width:150px;"/>
            </td>
        </tr>
        <tr id="ali_account_td">
            <td  class="td" align="right" width="40%"><lable for="aliAccount">支付宝账号:</lable></td>
            <td  width="60%">
                <input id="ali_account" name="aliAccount" class="easyui-validatebox" data-options="missingMessage:'请输入支付宝账号', required:true" style="width:150px;"/>
            </td>
        </tr>
        <tr id="bank_name_td">
            <td  class="td" align="right" width="40%"><lable for="bankName">银行名称:</lable></td>
            <td  width="60%">
                <input id="bank_name" name="bankName" class="easyui-validatebox" data-options="missingMessage:'请输入银行名称', required:true" style="width:150px;"/>
            </td>
        </tr>
        <tr id="bank_opening_id">
            <td class="td" align="right" width="40%"><lable for="bankOpening">开户行信息:</lable></td>
            <td width="60%">
                <textarea id="bank_opening" name="bankOpening" class="easyui-validatebox" data-options="missingMessage:'请输入开户行信息',required:true"></textarea>
            </td>
        </tr>
        <tr>
            <td class="td" align="right" width="40%"><lable for="def">是否设为默认:</lable></td>
            <td width="60%">
                <select id="def" class="easyui-combobox" name="def" data-options="required:true,panelHeight:'auto',editable:false" style="width:160px;">
                    <option value="0" selected>否</option>
                    <option value="1">是</option>
                </select>
            </td>
        </tr>
    </table>
    <div style="margin-top: 20px;text-align: center">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'", onclick="insertUserAccount()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'", onclick="cancelInsertForm()">取消</a>
    </div>
</form>

<script type="text/javascript">

    function cancelInsertForm() {
        $('#user_acount_insert_dialog').dialog('close');
    }

    function insertUserAccount() {
        var userID = $("#userID").val();
        if (userID == null || userID == "" || userID.length <= 0) {
            $.messager.alert("提示", "用户信息出错!","info");
            return;
        }
        var type = $("#type").combobox("getValue");
        if (type == 0) {
            $("#wechat_account").val("");
            $("#ali_account").val("");
        } else {
            $("#bank_account").val("");
            $("#bank_name").val("");
            $("#bank_opening").val("");
            $("#bank_account").numberbox("setValue", "");
            if (type == 1) {
                // 支付宝
                $("#wechat_account").val("");
            } else {
                // 微信
                $("#ali_account").val("");
            }
        }
        var msg = "添加";
        var url = "/user/account/insert.do";

        lananUpdateOrInsert(msg, url, "insert_user_account_form", "user_acount_insert_dialog", "user_account")

//        $.messager.progress();
//        $("#insert_user_account_form").form("submit",{
//            url:url,
//            onSubmit:function(){
//                var valid = $(this).form("validate");
//                if (!valid) {
//                    $.messager.progress("close");
//                }
//                return valid;
//            },
//            success:function(data){
//                data=$.parseJSON(data);
//                $.messager.progress("close");
//                if(data.success){
//                    $("#user_acount_insert_dialog").dialog("close");
//                    $.messager.show({
//                        title: msg + "成功",msg: msg + "成功!",
//                        timeout:600,style:"left:30%;top:10%",
//                        showType:"fade"
//                    });
//                    $("#user_account").datagrid("reload");
//                    $('#user_account').datagrid('clearSelections');
//                }else{
//                    $.messager.alert(msg + "失败", data.msg,"error");
//                }
//            },
//            error:function () {
//                $.messager.progress("close");
//                $.messager.alert("操作失败", "服务器连接失败!","error");
//            }
//        });
    }

    $(function () {
        autoCompleteDate('${path}/user/address/autoCompleteData.do', 'autocomplete-ajax-search-account', 'userID', 'autocomplete-ajax-search-account-x');

        $("#wechat_account_td").hide();
        $("#ali_account_td").hide();
        $('#wechat_account').validatebox({ required: false });
        $('#ali_account').validatebox({ required: false });
        $("#type").combobox({
            onSelect: function () {
                var select = $("#type").combobox('getValue')
                if (select == '0') {
                    $("#bank_name_td").show();
                    $("#bank_opening_id").show();
                    $("#bank_account_td").show();
                    $("#wechat_account_td").hide();
                    $("#ali_account_td").hide();

                    $('#bank_account').numberbox({ required: true });
                    $('#bank_name').validatebox({ required: true });
                    $('#bank_opening').validatebox({ required: true });
                    $('#wechat_account').validatebox({ required: false });
                    $('#ali_account').validatebox({ required: false });
                } else {
                    $("#bank_name_td").hide();
                    $("#bank_opening_id").hide();
                    $("#bank_account_td").hide();

                    $('#bank_account').numberbox({ required: false });
                    $('#bank_name').validatebox({ required: false });
                    $('#bank_opening').validatebox({ required: false });

                    if (select == '1') {
                        $("#ali_account_td").show();
                        $("#wechat_account_td").hide();

                        $('#ali_account').validatebox({ required: true });
                        $('#wechat_account').validatebox({ required: false });
                    } else {
                        $("#wechat_account_td").show();
                        $("#ali_account_td").hide();

                        $('#wechat_account').validatebox({ required: true });
                        $('#ali_account').validatebox({ required: false });
                    }
                }
            }
        })
    })
</script>
</body>
</html>
